package com.dyz.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dyz.domain.DTO.WebConfigDTO;
import com.dyz.domain.WebConfig;
import com.dyz.mapper.WebConfigMapper;
import com.dyz.model.Result;
import com.dyz.service.IWebConfigService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 网站配置信息 服务实现类
 * </p>
 *
 * @author dyz
 * @since 2025-04-19
 */
@Service
public class WebConfigServiceImpl extends ServiceImpl<WebConfigMapper, WebConfig> implements IWebConfigService {
    @Resource
    private WebConfigMapper webConfigMapper;

    @Override
    public Result<?> getConfigList(Page<WebConfig> page, String name, String type) {
        page.addOrder(OrderItem.desc("created"));
        Page<WebConfig> webConfigPage = webConfigMapper.getConfigList(page, name, type);
        return Result.success(webConfigPage);
    }

    @Override
    public Result<?> getOneObj(Long id) {
        WebConfig webConfig = webConfigMapper.selectById(id);
        return Result.success(webConfig);
    }

    @Override
    public Result<?> delete(String[] ids) {
        if(ids==null||ids.length==0){
            return Result.fail("请选择要删除的数据");
        }
        List<Long> idList = Arrays.stream(ids).map(Long::parseLong).collect(Collectors.toList());
        if(removeByIds(idList)){
            return Result.success("删除成功");
        }else{
            return Result.fail("删除失败");
        }
    }

}
